package Euler30;

import java.util.*;
import ReusableCode.*;

public class FifthPowerSum {
	public static void main(String[] args) {
		long totalSum = 0;
		List<Integer> nums = new ArrayList<Integer>();
		int powers[] = new int[10];
		
		for(int i = 0; i < powers.length; i++)
		{
			powers[i] = (int) Math.pow(i, 5);
		}
		
		System.out.println("Working...");
		
		for(int i = 2; i < 1000000; i++)
		{
			int digits[] = MathFunctions.getDigits(i);
			int sum = 0;
			
			for(int j = 0; j < digits.length; j++)
			{
				sum += powers[digits[j]];
			}
			
			if (sum == i)
			{
				nums.add(i);
				totalSum += sum;
			}
		}
		
		System.out.println(nums + "\nTotal sum is: " + totalSum);
	}
}
